package xiaoka.ecarx.com.cn.youlong.upnp;

import org.teleal.cling.binding.annotations.UpnpAction;
import org.teleal.cling.binding.annotations.UpnpInputArgument;
import org.teleal.cling.binding.annotations.UpnpOutputArgument;
import org.teleal.cling.binding.annotations.UpnpService;
import org.teleal.cling.binding.annotations.UpnpServiceId;
import org.teleal.cling.binding.annotations.UpnpServiceType;
import org.teleal.cling.binding.annotations.UpnpStateVariable;

/**
 * Created by zoro on 2016/11/7.
 */

@UpnpService(
        serviceId = @UpnpServiceId("WifiMessageHandler"),
        serviceType = @UpnpServiceType(value = "WifiMessageHandler", version = 1)
)
public class WifiMessageHandler {

    @UpnpStateVariable(defaultValue = "")
    private String msg = "";

    @UpnpStateVariable(defaultValue = "")
    private String from = "";

    @UpnpAction(out = @UpnpOutputArgument(name = "Ret"))
    public String setMsg(@UpnpInputArgument(name = "Msg") String newMsg,
                         @UpnpInputArgument(name = "From") String from) {
        this.msg = newMsg;
        this.from = from;
        System.out.println("receive new msg:" + newMsg);
        //对异常信息进行处理
        if (newMsg == null&&from==null) {
            return "error";
        }
        //通过单列模式，进行消息处理
      //  MainActivity.mInstance.messageReceived(newMsg,from);
        return "Received";
    }
}
